package main

import "fmt"

func maxArea(height []int) int {
	max := 0
	left, right := 0, len(height)-1

	for left < right {
		hleft, hright := height[left], height[right]
		area := (right - left) * Min(hleft, hright)

		max = Max(area, max)

		if hleft > hright {
			right--
		} else {
			left++
		}
	}

	return max
}

func main() {
	fmt.Println(maxArea([]int{1, 8, 6, 2, 5, 4, 8, 3, 7}))
}

func Min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func Max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
